package network;

import java.io.IOException;
import java.net.SocketException;
import java.util.HashMap;
import java.util.Map;

//使用继承，是为了复用之前的代码
public class UdpDictServer extends UdpEchoServer{
    private Map<String,String > dict = new HashMap<>();

    public UdpDictServer(int port) throws SocketException {
        super(port);
        dict.put("dog","小狗");
        dict.put("cat","小猫");
        dict.put("apple","苹果");
        dict.put("bear","熊");
        //这里可以添加无限个数据
    }
    @Override
    public String process(String request){
        return dict.getOrDefault(request,"该单词没有查到！");
    }

    public static void main(String[] args) throws IOException {
        UdpDictServer udpDictServer = new UdpDictServer(9090);
        //这里调用start方法是父类中写的
        udpDictServer.start();
    }
}
